#pragma once

#include<QObject>
#include<QStandardItemModel>
#include <CubeFeature.h>
#include <ConeFeature.h>
#include <CylinderFeature.h>
#include <SphereFeature.h>
#include <TorusFeature.h>
#include <baseFeature.h>
#include <BrepFeature.h>
#include <FilletFeature.h>
#include <TransformFeature.h>
#include <StretchFeature.h>
#include <RevolFeature.h>
#include <HollowFeature.h>

class modelSoft;
class storeManager :public QObject{
	Q_OBJECT
public:
	storeManager(modelSoft* myModelSoft, QObject* parent = nullptr);
	~storeManager();
	void saveToFile(std::string fileName);
	int stringToFeature(std::string str);
	bool isFileEmpty(const std::string& filename) {
		std::ifstream file(filename, std::ios::binary);
		// 如果文件无法打开，返回true表示为空
		if (!file.is_open()) {
			std::cerr << "Error opening file: " << filename << std::endl;
			return true;
		}
		// 检查文件指针是否已经到达文件末尾
		return file.peek() == std::ifstream::traits_type::eof();
	}
	void clearFile(const std::string& filename) {
		std::ofstream file(filename, std::ios::trunc);
		// 如果文件无法打开，输出错误信息
		if (!file.is_open()) {
			std::cerr << "Error opening file for clearing: " << filename << std::endl;
		}
		else {
			std::cout << "File has been cleared: " << filename << std::endl;
		}
	}
protected:
	CubeFeature* writeIntoCubeFeature(std::string readStr);
	ConeFeature* writeIntoConeFeature(std::string readStr);
	CylinderFeature* writeIntoCylinderFeature(std::string readStr);
	SphereFeature* writeIntoSphereFeature(std::string readStr);
	TorusFeature* writeIntoTorusFeature(std::string readStr);
	BrepFeature* writeIntoBrepFeature(std::string readStr);
	FilletFeature* writeIntoFilletFeature(std::string readStr);
	TransformFeature* writeIntoTransformFeature(std::string readStr);
	StretchFeature* writeIntoStretchFeature(std::string readStr);
	RevolFeature* writeIntoRevolFeature(std::string readStr);
	HollowFeature* writeIntoHollowFeature(std::string readStr);

private:
    std::string txtName;
	modelSoft* myModelSoft;
	QStandardItemModel* historyTree;
};